import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_widgets/pages/base/base_tab_page.dart';
import 'package:kq_flutter_widgets/resources/kq_theme_colors.dart';
import 'package:kq_flutter_core_widget/utils/toast_util.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_head_button.dart';
import 'package:kq_flutter_widgets/widgets/emptyView/empty_view.dart';
import 'package:kq_flutter_widgets/widgets/tabbar/kq_tab_bar.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

/// TabBar 演示页面
class TabBarDemoPage extends BaseTabPage {
  const TabBarDemoPage({super.key});

  @override
  BaseTabPageState<BaseTabPage> getState() => _TabBarDemoPageState();
}

class _TabBarDemoPageState extends BaseTabPageState<TabBarDemoPage> {
  var _indicatorType = IndicatorType.roundBg;

  @override
  List<TabDataEntity> getTabNames() {
    return [
      TabDataEntity('待返修', number: 1),
      TabDataEntity('返修中', number: 999),
      TabDataEntity('已返修', number: 66),
      TabDataEntity('待返修', number: 1),
      TabDataEntity('返修中', number: 999),
      TabDataEntity('已返修', number: 66),
      TabDataEntity('待返修', number: 1),
      TabDataEntity('返修中', number: 999),
      TabDataEntity('已返修', number: 66),
    ];
  }

  @override
  int getInitialPage() {
    return 0;
  }

  @override
  TabBarIndicatorSize? getIndicatorSize() {
    return TabBarIndicatorSize.label;
  }

  @override
  IndicatorType getIndicatorType() {
    return _indicatorType;
  }

  @override
  PreferredSizeWidget? buildAppBar() {
    return KqHeadBar(
      headTitle: 'KqTabBar演示',
      back: () {
        Get.back();
      },
      actions: KqHeadButton(
        buttonType: KqHeadButtonType.text,
        widget: Text(
          '切换',
          style: TextStyle(fontSize: 12.sp, color: KqThemeColors.bgWhite),
        ),
        onTap: () {
          setState(() {
            _indicatorType = _indicatorType == IndicatorType.roundBg
                ? IndicatorType.underline
                : IndicatorType.roundBg;
          });
        },
      ),
    );
  }

  @override
  onPageChanged(int index, TabDataEntity entity) {
    KqToast.showNormal('第$index页');
  }

  @override
  List<Widget> buildPageViews(List<TabDataEntity> tabs) {
    return tabs.map((e) => const KqEmptyView(
      text: '未找到匹配的结果',
      bottomHintString: '仅支持以下内容查询：产品名称，产品编号，计划单号，模具名称，模具编号，规格型号，模具编号，规格型号',)).toList();
  }
}
